#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f;

int n;
int a[N];
map<int, int> idx;
map<int, vector<int>> g;

vector<int> p;
bool st[N];

void get_primes(int n)
{
    for (int i = 2; i <= n; i++) {
        if (!st[i]) p.push_back(i);
        for (int j = 0; j < p.size() && p[j] * i <= n; j++) {
            st[p[j] * i] = 1;
            if (i % p[j] == 0) break;
        }
    }
}

void solve()
{
    cin >> n;
    memset(a, 0, sizeof a);
    g.clear();idx.clear();

    g[1].push_back(1);a[1] = 1;
    for (int i : p) {
        if (i > n) break;
        for (int j = 1;i * j <= n;j++) {
            int x = i * j;
            if (a[x] != 0) {
                int t = a[x];
                auto it = lower_bound(g[t].begin(), g[t].end(), x);
                if (it != g[t].end() && (*it) == x) g[t].erase(it);
            }
            a[x] = i;
            g[i].push_back(x);
        }
    }

    for (int i = 1;i <= n;i++) {
        int x = a[i];
        cout << g[x][(++idx[x]) % g[x].size()] << ' ';
    }
    cout << '\n';
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    get_primes(100000);
    cin >> T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}